package cn.seapon.talker;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.seapon.talker.common.UserInformation;
import cn.seapon.talker.infocarrier.SharedItems;

public class FriendDetailActivity extends Activity implements OnClickListener{
	private static final String TAG = "||__FriendDetailActivity__||";
	
	private UserInformation userinfo;
	
	private ImageView iv_avatar;
	private TextView tv_account;
	private TextView tv_nickname;
	private TextView tv_phone;
	private TextView tv_email;
	private Button make_friend_btn;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_friend_detail);
		iv_avatar = (ImageView) findViewById(R.id.iv_avatar);
		tv_account = (TextView) findViewById(R.id.tv_account);
		tv_nickname = (TextView) findViewById(R.id.tv_nickname);
		tv_phone = (TextView) findViewById(R.id.tv_phone);
		tv_email = (TextView) findViewById(R.id.tv_email);
		make_friend_btn = (Button) findViewById(R.id.make_friend_btn);
		
		//不存在时返回false
		userinfo = (UserInformation) getIntent().getExtras().get("userinfo");
		if (userinfo == null) {
			Toast.makeText(this, "无法获取用户信息!", Toast.LENGTH_SHORT).show();
			return ;
//			Log.e(TAG, "无法获取用户信息");
		}
		if (userinfo.getAccount().equals(SharedItems.userInformation.getAccount())) {
			make_friend_btn.setVisibility(View.INVISIBLE);
		}
		tv_account.setText(userinfo.getAccount());
		tv_nickname.setText(userinfo.getNickname());
		tv_phone.setText(userinfo.getPhone());
		tv_email.setText(userinfo.getEmail());
		if (!TextUtils.isEmpty(userinfo.getAvatar())) {
			iv_avatar.setImageResource(SharedItems.avatarMap.get(userinfo.getAvatar()));
		}
		
		make_friend_btn.setOnClickListener(this);
	}


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.make_friend_btn:
			Intent intent = new Intent();
			intent.setClass(this,SendFriendRequestActivity.class);
			intent.putExtra("userid", userinfo.getAccount());
			startActivity(intent);
			break;

		default:
			break;
		}
	}

}
